package com.basics.framework.config.jwt;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

public class BLContext {

    //日志
    private static Logger log = LoggerFactory.getLogger(BLContext.class);

    private static ThreadLocal<Map<String, Object>> threadLocalMap = new ThreadLocal<Map<String,Object>>();

    public static void setValue(String key, Object value) {
        Map<String, Object> map = threadLocalMap.get();
        if (map == null) {
            map = new HashMap<String, Object>();
            threadLocalMap.set(map);
        }
        map.put(key, value);
    }

    public static Object getValue(String key) {
        Map<String, Object> map = threadLocalMap.get();
        if (map == null) {
            return null;
        }
        return map.get(key);
    }

    public static void setMap(Map<String, Object> map) {
        threadLocalMap.set(map);
    }

    public static Map<String, Object> getMap() {
        return threadLocalMap.get();
    }

    public static void clear() {
        threadLocalMap.remove();
    }
}
